package com.itheima.dao;

import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Role;
import com.itheima.pojo.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface UserMapper {

    User userByUserName(@Param("username") String username);

    @Update("update t_user set password = #{pass} where username = #{username} ")
    void changePassword(@Param("pass") String pass, @Param("username") String username);

    List<User> findPage(@Param("queryString")String queryString);

    @Select("select * from t_user where id = #{id}")
    User findByid(@Param("id")Integer id);

    @Select("select role_id from t_user_role where user_id = #{id}")
    List<Integer> findUserAndRole(Integer id);

    @Select("select * from t_role")
    Set<Role> roleFindAll();

    void updata(User user);

    @Delete("delete from t_user_role where user_id=#{userId}")
    void deleteUserAndRoleById(@Param("userId") Integer userId);

    void addUserAndRole(@Param("userAndrole") List<Map> userAndrole);

    void add(User user);

    @Delete("delete from t_user where id=#{id}")
    void delete(@Param("id") Integer id);

    Integer findIdByUsername(@Param("username") String username);
}
